package com.lam.generator.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.lam.common.utils.CollectionUtil;
import com.lam.common.utils.StringUtils;
import com.lam.generator.entity.GenTableExtConfig;
import com.lam.generator.mapper.GenTableExtConfigMapper;
import com.lam.generator.param.GenTableExtConfigParam;
import com.lam.generator.service.GenTableExtConfigService;

/**
 * 代码生成配置信息Service业务层处理
 * 
 * @author admin
 * @date 2022-11-02
 */
@Service
public class GenTableExtConfigServiceImpl implements GenTableExtConfigService {

    @Autowired
    private GenTableExtConfigMapper genTableExtConfigMapper;

    /**
     * 查询代码生成配置信息
     * 
     * @param id ID
     * @return 单个对象
     */
    @Override
    @Transactional(readOnly = true)
    public GenTableExtConfig selectByTableId(String tableId) {

    	QueryWrapper<GenTableExtConfig> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("table_id", tableId);
        return CollectionUtil.getFirst(genTableExtConfigMapper.selectList(queryWrapper));
    }
    
    /**
     * 查询代码生成配置信息
     * 
     * @param id ID
     * @return 单个对象
     */
    @Override
    @Transactional(readOnly = true)
    public GenTableExtConfig selectById(String id) {

        return genTableExtConfigMapper.selectById(id);
    }

    /**
     * 查询代码生成配置信息列表
     * 
     * @param param
     * @return 
     */
    @Override
    @Transactional(readOnly = true)
    public List<GenTableExtConfig> selectList(GenTableExtConfigParam param) {
    
        QueryWrapper<GenTableExtConfig> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq(StringUtils.isNotBlank(param.getTableId()), "table_id", param.getTableId());
        return genTableExtConfigMapper.selectList(queryWrapper);
    }

    /**
     * 新增代码生成配置信息
     * 
     * @param genTableExtConfig 
     * @return 
     */
    @Override
    @Transactional
    public int insert(GenTableExtConfig genTableExtConfig) {
    
        return genTableExtConfigMapper.insert(genTableExtConfig);
    }

    /**
     * 修改代码生成配置信息
     * 
     * @param genTableExtConfig 
     * @return 
     */
    @Override
    @Transactional
    public int update(GenTableExtConfig genTableExtConfig) {
    
        return genTableExtConfigMapper.updateById(genTableExtConfig);
    }

    /**
     * 删除代码生成配置信息信息
     * 
     * @param idStr ID，多个用逗号分隔
     * @return 
     */
    @Override
    @Transactional
    public int deleteById(String idStr) {
    
        if(StringUtils.isBlank(idStr)) {
            return 0;
        }
        return genTableExtConfigMapper.deleteBatchIds(StringUtils.str2List(idStr));
    }
    
    
}
